package pl.edu.pjwstk.kor.sbql4j.project2;

import pl.wcislo.sbql4j.db4o.Db4oSBQLQuery;
import java.util.Collection;
import com.db4o.ObjectContainer;
import pl.edu.pjwstk.kor.database.Database;
import pl.edu.pjwstk.kor.database.Sbql4jQuery;
import pl.edu.pjwstk.kor.model.Customer;
import pl.edu.pjwstk.kor.model.Deal;
import pl.edu.pjwstk.kor.model.Employee;
import pl.edu.pjwstk.kor.model.Rank;

public class Project2Query implements Sbql4jQuery {
    private Database database;
    
    public Project2Query() {
        super();
    }
    
    public void setDatabase(Database db) {
        this.database = db;
    }
    
    public Collection<Employee> query1(int dealCount) {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project2Query_SbqlQuery0(db,dealCount).executeQuery();
        Collection<Employee> emps = (Collection<Employee>)res;
        return emps;
    }
    
    public Collection<Customer> query2(String streetName) {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project2Query_SbqlQuery1(db,streetName).executeQuery();
        Collection<Customer> customers = (Collection<Customer>)res;
        return customers;
    }
    
    public Collection<Deal> query3(String jobName, int dealYear) {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project2Query_SbqlQuery2(db,jobName,dealYear).executeQuery();
        Collection<Deal> deals = (Collection<Deal>)res;
        return deals;
    }
    
    public Collection<Customer> query4(double dealCost) {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project2Query_SbqlQuery3(db,dealCost).executeQuery();
        Collection<Customer> customers = (Collection<Customer>)res;
        return customers;
    }
    
    /**
     * #{ db.((Rank as r) where not(count(r.customers.deals.cost) > 2100000)) };
     * not >
     */
    public Collection<Rank> query5(double dealCost) {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project2Query_SbqlQuery4(db,dealCost).executeQuery();
        Collection<Rank> ranks = (Collection<Rank>)res;
        return ranks;
    }
    
    /**
     * #{ db.((Customer as c) where c.ranks.groupName != "Partner biznesowy" and count(c.deals) >= 5) };
     * != i >=
     */
    public Collection<Customer> query6() {
        ObjectContainer db = database.getObjectContainer();
        Object res = new Project2Query_SbqlQuery5(db).executeQuery();
        Collection<Customer> customers = (Collection<Customer>)res;
        return customers;
    }
    
    /**
     * #{ 2+9*2/2%3 };
     * @return
     */
    public int query7() {
        Object res = new Project2Query_SbqlQuery6().executeQuery();
        return (Integer)res;
    }
}